home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
mgabra.zip
/
MGNET.C
< prev
next >
Wrap
Text File
|
1990-02-05
|
39KB
|
1,716 lines
/*****************************************
NETWORK FUNCTION LIBRARY
*****************************************/
/*
The following library was built over several years of hacking with the
Novell OS. Not all the code is guaranteed to exemplify good programming.
(In fact, some of it is darnright embarrassing). The nastiest part of
dealing with the Novell OS is the fact that integers (2 bytes) and
especially troublesome long integers (4 bytes) are swapped in their
byte order. You don't have to worry about that because these functions
handle that. However be careful. I haven't always written everything
clearly enough to show which swapping return values or parameters
should have.
Not all the functions available are here by far. These are just the
ones I found necessary while writing Utilities.
I recently rewrote some of the library to use dynamic (on stack) buffers
for the packets. Before I was using statics which consumed data space in
an unnecessarily wasteful manner. I haven't been able to test ALL the
rewritten functions for bugs. If you do have trouble it helps to have the:
APPLICATION PROGRAMMER'S GUIDE TO NETWARE AND FUNCTION CALL REFERENCE
Which is available from Novell.
Walt Howard
1-31-90
*/
#include <dos.h>
#include <string.h>
#include <stdio.h>
#include <dir.h>
#define WILD 0xFFFF
#define UNKNOWN_TYPE 0
#define NET_USER 1
#define USER_GROUP 2
#define PRINT_SERVER 3
#define FILE_SERVER 4
#define SENDFUNC 0xE1
#define LACKOFSPACE 0xFE
#define DOSSERVICE 0x21
#define MAXBROAD 60
#define LOGFUNC 0xE3
#define DIRFUNC 0xE2
#define TSR 1
#define GETMAP 0x01
#define MAXPATHLENGTH 64
#define GETFILEINFO 0x0f
#define ALLOCATEBASE 0x12
#define GETOBJECT 0x16
#define SCANBIND 0x37
#define READPROP 0x3D
#define SEARCH_PATTERN_LENGTH 20
#define BINDERY 0xE3
#define BUZZ 0x00
#define CASTOFF 0x02
#define CASTON 0x03
#define PREF 0xF0
#define FILEINFO 0x0F
#define GETIDNAME 0x36
#define MAXSTATIONS 100
#define MAXSEND 60
#define WILD 0xFFFF
#define UNKNOWN_TYPE 0
#define NET_USER 1
#define USER_GROUP 2
#define PRINT_SERVER 3
#define FILE_SERVER 4
#define GETOBJECT 0x16
#define SCANBIND 0x37
#define SEARCH_PATTERN_LENGTH 20
#define BINDERY 0xE3
#define MAXSTATIONS 100
#define COMMFUNC 0xE1
#define OPENPIPE 0x06
#define GETMSG 0x05
#define SENDMSG 0x04
#define PIPESTAT 0x08
#define CLOSEPIPE 0x07
#define MAXMSG 126
#define PIPEGOOD 0x00
#define PIPEHALF 0xFE
#define NOSTATION 0xFF
typedef int NATIVE;
typedef int WORD;
typedef long LONG;
typedef char BYTE;
BYTE spare;
typedef unsigned int REGISTER;
union trans {
char byte[4];
int intval;
long longval;
} transform;
/*****************************************
NETCALL
*****************************************/
int netcall(BYTE funcfamily, void far *req, void far *rep)
{
int rval;
#ifdef TSR
swapno();
#endif
_DI = FP_OFF(rep);
_SI = FP_OFF(req);
_ES = FP_SEG(rep);
_DS = FP_SEG(req);
_AL = 0;
_AH = funcfamily;
geninterrupt(0x21);
rval = (int) _AL;
#ifdef TSR
swapyes();
#endif
return(rval);
}
/*****************************************
BYTE ORDER SWAPPING FUNCTIONS
*****************************************/
long swaplong(long longint)
{
transform.longval = longint;
spare = transform.byte[0];
transform.byte[0] = transform.byte[3];
transform.byte[3] = spare;
spare = transform.byte[1];
transform.byte[1] = transform.byte[2];
transform.byte[2] = spare;
return(transform.longval);
}
/*****************************************
SWAPINT
*****************************************/
int swapint(int val)
{
transform.intval = val;
spare = transform.byte[0];
transform.byte[0] = transform.byte[1];
transform.byte[1] = spare;
return(transform.intval);
}
#define PROPERTY_SET 0x02
#define GETOBJECTID 0x35
#define ENVIRONMENT 0xF3
#define ADDTRUSTEE 0x0d
#define CREATEOBJECT 0x32
#define ADDPROPERTY 0x39
#define MAXOBJECTNAMELENGTH 128
#define MAXPROPERTYNAMELENGTH 128
#define ADDVALUE 0x41
#define MAXMEMBERNAMELENGTH 128
#define ADDITEMVALUE 0x3e
#define SET 0x02
#define ITEM 0x00
/* SECURITY DEFINES */
#define READ_ANYONE 0xf0
#define READ_ANYONE_LOGGED 0xf1
#define READ_OBJECT_OR_SUPERVISOR 0xf2
#define READ_SUPERVISOR 0xf3
#define READ_BINDERY 0xf4
#define WRITE_ANYONE 0x0f
#define WRITE_ANYONE_LOGGED 0x1f
#define WRITE_OBJECT_OR_SUPERVISOR 0x2f
#define WRITE_SUPERVISOR 0x3f
#define WRITE_BINDERY 0x4f
/*****************************************
NOVELL PIPE FUNCTIONS
*****************************************/
#define COMMFUNC 0xE1
#define OPENPIPE 0x06
#define GETMSG 0x05
#define SENDMSG 0x04
#define PIPESTAT 0x08
#define CLOSEPIPE 0x07
#define MAXMSG 126
#define PIPEGOOD 0x00
#define PIPEHALF 0xFE
#define NOSTATION 0xFF
/*****************************************
BINDFINDFIRST
*****************************************/
static LONG lastobject;
int bindfindfirst(WORD patterntype, char *pattern)
{
int rval;
struct {
NATIVE packetlength;
BYTE function;
LONG lastobjectseen;
WORD patterntype;
BYTE patternlength;
BYTE searchpattern[SEARCH_PATTERN_LENGTH];
} send;
struct {
NATIVE packetlength;
LONG uniqueobjectid;
WORD objecttype;
BYTE objectname[48];
BYTE objectflags;
BYTE objectsecurity;
BYTE propertiesexist;
} recv;
lastobject = -1;
send.lastobjectseen = swaplong(lastobject);
lastobject = send.lastobjectseen;
send.packetlength = sizeof(send) - sizeof(send.packetlength);
send.function = SCANBIND;
send.patterntype = swapint(patterntype);
stpcpy(send.searchpattern, pattern);
send.patternlength = strlen(send.searchpattern);
recv.packetlength = sizeof(recv);
rval = (int) netcall(BINDERY, &send, &recv);
lastobject = recv.uniqueobjectid;
return(rval);
}
/*****************************************
BINDFINDNEXT
*****************************************/
long bindfindnext(void)
{
int rval;
struct {
NATIVE packetlength;
BYTE function;
LONG lastobjectseen;
WORD patterntype;
BYTE patternlength;
char searchpattern[SEARCH_PATTERN_LENGTH];
} send;
struct {
NATIVE packetlength;
LONG uniqueobjectid;
WORD objecttype;
BYTE objectname[48];
BYTE objectflags;
BYTE objectsecurity;
BYTE propertiesexist;
} recv;
send.packetlength = sizeof(send) - sizeof(send.packetlength);
send.function = SCANBIND;
send.lastobjectseen = lastobject;
recv.packetlength = sizeof(recv);
rval = netcall(BINDERY, &send, &recv);
lastobject = recv.uniqueobjectid;
return(rval);
}
/*****************************************
GETOBJECTID
*****************************************/
long getobjectid(char *name, WORD objecttype)
{
int rval;
long temp;
struct {
NATIVE packetlength;
BYTE function;
WORD objecttype;
BYTE objectnamelength;
BYTE objectname[MAXOBJECTNAMELENGTH];
} send;
struct {
NATIVE packetlength;
LONG objectid;
WORD objecttype;
BYTE objectname[MAXOBJECTNAMELENGTH];
} recv;
send.function = GETOBJECTID;
send.objecttype = swapint(objecttype);
send.objectnamelength = (char) strlen(name);
strcpy(send.objectname, name);
send.packetlength = send.objectnamelength + 4;
recv.packetlength = 54;
recv.objectid = 0L;
rval = netcall(BINDERY, &send, &recv);
temp = swaplong(recv.objectid);
if (rval == 0) return(temp);
return(0L);
}
/****************************************
READ PROPERTY
****************************************/
char *getproperty(char *user, char *property)
{
int rval;
int temp;
char send[256];
struct {
NATI